feat(go): add float16 support to go#3235
Conversation
|
Hey @chaokunyang |
|
Hey @chaokunyang |
|
Create separate test files is better, I will check it later. And merge it if everything goes right |
Okk, in the meantime i'll try adding |
## Why? To handle `float16` arrays and slices in a cleaner way during serialization and deserialization in the Go. ## What does this PR do? - Modified the `createSerializer` function in `go/fory/type_resolver.go` to correctly return `float16SliceSerializer` for `reflect.Slice` of `float16` and `float16ArraySerializer` for `reflect.Array` of `float16`. - Added tests in `type_test.go` to validate this behavior. ## Related issues #3235 implementation for `float16` support #3310 `bfloat` implementation that aligns with this PR ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark
Referenced Issue - #3206
I've gone through the references in the #3206 issue and here are my implementation plans for the
float16type in go.Implementation Plan
go/fory/float16float16.go): Create a newFloat16type based onuint16to hold the raw bits, implementing essential constants (NaN,Inf) and conversion methods (FromFloat32(),Float32()) that handle IEEE 754 logic.Add,Sub,Mul,Div) by temporarily promoting values tofloat32for calculation, along with classification helpers likeIsNaN,IsFinite, and strict IEEE 754 comparison methods (Equal,Less).float16_serializer.go): Develop a dedicatedfloat16Serializerthat handles writing the 2-byte structure to the wire with the correctFLOAT16tag and reading it back.types.go,primitive.go): Update the Fory type system to recognizefloat16by adding new Dispatch IDs (PrimitiveFloat16DispatchId), registering the serializer, and setting the fixed size to 2 bytes.writer.go,reader.go,array_primitive.go): Modify the main read/write loops to process the new Dispatch IDs and add support for efficient[]float16arrays using theFLOAT16_ARRAYwire type.What's implemented so far:
Float32FromFloat16()andFloat32()which properly handles the exception types, IsNaN, IsInf, overflow, underflow of exponential and mantissa.float16.go.float16_serializer.gowhich includes, read and write methods forfloat16, basically a I/O driver for float16 type.float16_slice_serializer.go, a serializer for[]float16.Floattype.float16_array_serializer.goa seriailzer for[N]float16.Floattype.